/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.odinproject.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.odinproject.entity.OdinProject;
import com.jeesite.modules.odinproject.service.OdinProjectService;

/**
 * 工程表Controller
 * @author vic.duan
 * @version 2018-03-12
 */
@RestController
@RequestMapping(value = "${adminPath}/odinproject/odinProject")
public class OdinProjectController extends BaseController {

	@Autowired
	private OdinProjectService odinProjectService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public OdinProject get(String id, boolean isNewRecord) {
		return odinProjectService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("odinproject:odinProject:view")
	@RequestMapping(value = {"list", ""})
	public String list(OdinProject odinProject, Model model) {
		model.addAttribute("odinProject", odinProject);
		return "modules/odinproject/odinProjectList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("odinproject:odinProject:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<OdinProject> listData(OdinProject odinProject, HttpServletRequest request, HttpServletResponse response) {
		Page<OdinProject> page = odinProjectService.findPage(new Page<OdinProject>(request, response), odinProject); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("odinproject:odinProject:view")
	@RequestMapping(value = "form")
	public String form(OdinProject odinProject, Model model) {
		model.addAttribute("odinProject", odinProject);
		return "modules/odinproject/odinProjectForm";
	}

	/**
	 * 保存工程表
	 */
	@RequiresPermissions("odinproject:odinProject:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated OdinProject odinProject) {
		odinProjectService.save(odinProject);
		return renderResult(Global.TRUE, "保存工程表成功！");
	}
	
	/**
	 * 删除工程表
	 */
	@RequiresPermissions("odinproject:odinProject:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(OdinProject odinProject) {
		odinProjectService.delete(odinProject);
		return renderResult(Global.TRUE, "删除工程表成功！");
	}
	
}